if (!require(maps)) install.packages("maps")
## Loading required package: maps
if (!require(purrr)) install.packages("purrr")
## Loading required package: purrr
##
## Attaching package: 'purrr'
## The following object is masked from 'package:maps':
##
## map
if (!require(ggmap)) install.packages("ggmap")
## Loading required package: ggmap
## Loading required package: ggplot2
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
if (!require(tidyr)) install.packages("tidyr")
## Loading required package: tidyr
library(maps)
library(purrr)
library(ggmap)
library(tidyr)
#api <- Aquí se ponen las credencias de una geocoding api
register_google(key = api)
getOption("ggmap")
#Generar una nueva columna con la longitud y latitud según la localicación (location)
rcn_flw_data <- rcn_flw_data %>%
mutate(longlat = purrr::map(.$location, geocode))
#Seleccionar algunas columnas
rcn_flw_dataSelect <-rcn_flw_data %>%select(screen_name, created_at, followers_count, statuses_count,location, longlat)
# Separar la columana longlat en dos columnas
rcn_flw_dataSelect<-rcn_flw_dataSelect%>% unnest()
# Elimnar las filas que tienen NA
rcn_flw_dataSelect<-na.omit(rcn_flw_dataSelect)
if (!require(ggthemes)) install.packages("ggthemes")
## Loading required package: ggthemes
library(ggthemes)
library(ggplot2)
El valor del alpha es para la transparencia de los puntos, 1- color normal, menor que 1 se le va dando transparencia.
world <- ggplot() +
borders("world", colour = "gray85", fill = "gray80") +
ggthemes::theme_map()
map <- world +
geom_point(aes(x = lon, y = lat,
group=location,
size = followers_count),
data = rcn_flw_dataSelect, colour = 'red', alpha =.3) +
scale_size_continuous(breaks = c(250, 500, 750, 1000)) +
labs(size = 'Followers')
map
if (!require(plotly)) install.packages("plotly")
## Loading required package: plotly
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggmap':
##
## wind
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
if (!require(gganimate)) install.packages("gganimate")
## Loading required package: gganimate
library(plotly)
Usemos el mapa creado anteriormente para mostarlo dinámicamente, con ggplotly
m<-plotly::ggplotly(map, tooltip = c('group','size'))
m
if (!require(leaflet)) install.packages("leaflet")
## Loading required package: leaflet
library(leaflet)
m <- leaflet(rcn_flw_dataSelect) %>%addTiles()
m %>% addCircles(lng = ~lon, lat = ~lat, popup = rcn_flw_dataSelect$location, weight = 8, radius = 40, color = "#fb3004", stroke = TRUE, fillOpacity = 0.8)